package com.googlecode.gwtbb.client.only.widget.form.entry;

import com.google.gwt.user.client.ui.HasHorizontalAlignment;
import com.google.gwt.user.client.ui.HasVerticalAlignment;
import com.google.gwt.user.client.ui.Widget;
import org.apache.commons.collections.comparators.ComparableComparator;
import org.apache.commons.collections.comparators.ReverseComparator;

import java.util.Comparator;

/**
 * @author Abraham Grief
 * @version $Id$
 * @since Apr 30, 2008
 */
public class WidgetCell implements HasHorizontalAlignment, HasVerticalAlignment {
	public static final Comparator<WidgetCell> TOP_DOWN = new Comparator<WidgetCell>() {
		public int compare(WidgetCell wc1, WidgetCell wc2) {
			int rowCompare = ComparableComparator.getInstance().compare(wc1.getRow(), wc2.getRow());
			return rowCompare != 0 ? rowCompare : ComparableComparator.getInstance().compare(wc1.getCol(), wc2.getCol());
		}
	};

	/**
	 * @noinspection unchecked
	 */
	public static final Comparator<WidgetCell> BOTTOM_UP = new ReverseComparator(TOP_DOWN);
	private final Widget widget;
	private final int row;
	private final int col;
	private final int colSpan;
	private final int rowSpan;
	private final HorizontalAlignmentConstant horizontalAlignment;
	private final VerticalAlignmentConstant verticalAlignment;

	public WidgetCell(Widget widget, int row, int col, int rowSpan, int colSpan, HasHorizontalAlignment.HorizontalAlignmentConstant horizontalAlignment, HasVerticalAlignment.VerticalAlignmentConstant verticalAlignment) {
		this.widget = widget;
		this.row = row;
		this.col = col;
		this.rowSpan = rowSpan;
		this.colSpan = colSpan;
		this.horizontalAlignment = horizontalAlignment;
		this.verticalAlignment = verticalAlignment;
	}

	public int getCol() {
		return col;
	}

	public int getColSpan() {
		return colSpan;
	}

	public HorizontalAlignmentConstant getHorizontalAlignment() {
		return horizontalAlignment;
	}

	public int getRow() {
		return row;
	}

	public int getRowSpan() {
		return rowSpan;
	}

	public VerticalAlignmentConstant getVerticalAlignment() {
		return verticalAlignment;
	}

	public Widget getWidget() {
		return widget;
	}

	public void setHorizontalAlignment(HorizontalAlignmentConstant align) {
		throw new UnsupportedOperationException("read-only property");
	}

	public void setVerticalAlignment(VerticalAlignmentConstant align) {
		throw new UnsupportedOperationException("read-only property");
	}
}
